package com.sas.web.clients;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.form.AjaxButton;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.ResourceModel;

import com.sas.domain.Client;
import com.sas.model.EntityModel;
import com.sas.web.BasePage;
import com.sas.web.panel.clients.ClientInfoShowPanel;

public class ClientSinglePage extends BasePage {

	public ClientSinglePage(final IModel<Client> iModel, final ModalWindow modal1) {
		Form<Client> form = new Form<Client>("form", new CompoundPropertyModel<Client>(new EntityModel<Client>(Client.class, iModel.getObject())));
		final ClientInfoShowPanel cip = new ClientInfoShowPanel("clientInfo");
		cip.setEnable(false);
		form.add(cip);
		
		final AjaxButton save = new AjaxButton("save", new ResourceModel("save"), form) {

			@Override
			protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
				modal1.close(target);
			}
		};

		form.add(new Button("edit", new ResourceModel("edit")) {
			@Override
			public void onSubmit() {
				cip.setEnable(true);
				save.setEnabled(true);
			}
		});

		save.setEnabled(false);
		form.add(save);

		FeedbackPanel feedback = new FeedbackPanel("feedback");
		add(feedback);
		add(form);
	}

}
